#include "../../server/rpc_server.hpp"
#include "../../common/detail.hpp"

// 服务接口
void Add(const Json::Value &req, Json::Value &rsp)
{
    int num1 = req["num1"].asInt();
    int num2 = req["num2"].asInt();
    rsp = num1 + num2;
}

int main()
{

    // 实例化一个服务对象: 对齐进行描述, 并且将我们定义的Add函数接口传入
    std::unique_ptr<tmh_rpc::server::SDescribeFactory> desc_factory(new tmh_rpc::server::SDescribeFactory());
    desc_factory->setMethodName("Add");
    desc_factory->setParamsDesc("num1", tmh_rpc::server::VType::INTEGRAL);
    desc_factory->setParamsDesc("num2", tmh_rpc::server::VType::INTEGRAL);
    desc_factory->setReturnType(tmh_rpc::server::VType::INTEGRAL);
    desc_factory->setCallback(Add);

    tmh_rpc::Address addr = {"127.0.0.1", 9090};
    tmh_rpc::Address reg_addr = {"127.0.0.1", 8080};

    // 启用服务注册功能, 并且传入服务注册地址,(在同一台云服务器上的两个服务, 端口号不同)
    tmh_rpc::server::RpcServer server(addr,true,reg_addr);

    // 将当前提供的服务注册进内部管理模块
    server.registerMethod(desc_factory->build());
    server.start();
    return 0;
}